local thbattle__qiujingye_diaoling = fk.CreateSkill {

  name = "thbattle__qiujingye_diaoling",

  tags = { Skill.Compulsory, },

}



thbattle__qiujingye_diaoling:addEffect(fk.AfterCardsMove, {
  name = "thbattle__qiujingye_diaoling",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(thbattle__qiujingye_diaoling.name) or player.phase == Player.NotActive then return end
    for _, move in ipairs(data) do
      if move.from and move.from ~= player and move.from:isKongcheng() then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(thbattle__qiujingye_diaoling.name)
    player.room:notifySkillInvoked(player, thbattle__qiujingye_diaoling.name, "drawcard")
    player:drawCards(1, thbattle__qiujingye_diaoling.name)
  end,
})
thbattle__qiujingye_diaoling:addEffect(fk.Damaged, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(thbattle__qiujingye_diaoling.name) and player.phase == Player.NotActive and
        player:isAlive() and
        player.room.current:getMark("@@thbattle__qiujingye_diaoling-turn") == 0
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(thbattle__qiujingye_diaoling.name)
    player.room:notifySkillInvoked(player, thbattle__qiujingye_diaoling.name, "masochism")
    THB_Utility.addStatusMark(player.room.current, "@@thbattle__qiujingye_diaoling-turn")
  end,
})

thbattle__qiujingye_diaoling:addEffect(fk.EventPhaseEnd, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@thbattle__qiujingye_diaoling-turn") > 0 and
    player.phase == Player.Discard and not player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askForDiscard(player, 1, 1, false, thbattle__qiujingye_diaoling.name, false, ".",
      "#thbattle__qiujingye_diaoling_discard-prompt")
    THB_Utility.removeStatusMark(player, "@@thbattle__qiujingye_diaoling")
  end,
})

return thbattle__qiujingye_diaoling
